package com.talkology.pilot.student.controller;

import com.talkology.pilot.database.model.Bookings;
import com.talkology.pilot.student.service.IBookingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/bookings")
public class BookingController {
    @Autowired
    private IBookingService service;


    @RequestMapping(value = "/all", method= RequestMethod.GET)
    @ResponseBody
    public List<Bookings> getBookingsByFilter(@RequestParam(value = "studentId", required = false) String studentId,
                                             @RequestParam(value = "teacherName", required = false) String teacherName,
                                             @RequestParam(value = "classBegin", required = false) String classBegin,
                                             @RequestParam(value = "classEnd", required = false) String classEnd,
                                             @RequestParam(value = "status", required = false) String status) {
        return service.getAllByFilter(studentId, teacherName, classBegin, classEnd,status);
    }

    @RequestMapping(value = "/info", method= RequestMethod.GET)
    @ResponseBody
    public Bookings getInfo(@RequestParam(value = "index", required = true) Integer index) {
        return service.getInfo(index);
    }

    @RequestMapping(value = "/add", method= RequestMethod.PUT)
    @ResponseBody
    public void addBookingsInfo(@RequestBody Bookings record) {
        service.add(record);
    }

    @RequestMapping(value = "/update", method= RequestMethod.PUT)
    @ResponseBody
    public void updateBookingsInfo(@RequestBody Bookings record) {
        service.edit(record);
    }

    @RequestMapping(value = "/delete", method= RequestMethod.DELETE)
    @ResponseBody
    public void deleteBookingsInfo(@RequestParam(value = "index", required = false) Integer index) {
        service.delete(index);
    }
}
